<#assign module="marketing"/>

<@override name="header">
</@override>
<@override name="body">
<div class="row">
 	<div class="col-xs-12">
 		<button class="pull-right btn btn-primary" onclick="window.location='${ctx}/activity/add';"><i class="icon-plus"></i>&nbsp;添加新活动</button>
	</div>
</div>
<div class="row margin-top">
	<div class="col-xs-12">
	<div class="panel panel-primary">
	<div class="table-responsive">
		<table class="table table-striped" id="table">
			<thead>
			<tr style="font-size:14px;">
				<th>状态</th>
				<th>活动名称</th>
				<th>活动对象</th>
				<th>活动事件</th>
				<th>活动类型</th>
				<@shiro.isMainCompany>
				<th>所属公司</th>
				</@shiro.isMainCompany>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				<#if (page.content)?? >
			  	<#list (page.content)?sort_by("sort")  as data>
					<tr>
						<td>
							<#if data.stoped>
								<span class="label label-default status-td">已停止</span>
							<#else>
								<#if data.timeStatus==0>
									<span class="label label-warning status-td">未开始</span>
								<#elseif data.timeStatus==1>
									<span class="label label-danger status-td">进行中</span>
								<#elseif data.timeStatus==2>
									<span class="label label-default status-td">已过期</span>
								</#if>
							</#if>
						</td>
						<td>
							${data.title?if_exists} 
							<@zhuan>
								<#if data.orderCarType=="daijia">
									<span class="label label-danger status-td">代</span>
								<#elseif data.orderCarType=="zhuanche">
									<span class="label label-warning status-td">专</span>
								<#else>
									<span class="label label-danger status-td">全</span>
								</#if>
							</@zhuan>
						</td>
						<td>
							<#if data.activityTarget??>
								<#if data.activityTarget=="all">
									所有客户
								<#elseif data.activityTarget=="passenger">
									个人客户
								<#elseif data.activityTarget=="enterprise">
									企业客户
								</#if>
							</#if>
						</td>
						<td>
							<#if data.activityEvent??>
								<#if data.activityEvent=="newRegister">
									新注册
								<#elseif data.activityEvent=="orderComplete">
									订单结算
								<#elseif data.activityEvent=="shareSuccess">
									分享成功${data.shareTimes?if_exists}次内
								<#elseif data.activityEvent=="orderCompleteTimes">
									每完成代驾${data.completeTimes?if_exists}次
								<#elseif data.activityEvent=="recharging">
									充值满${data.rechargingMoney?if_exists}元
								<#elseif data.activityEvent=="discount">
									折扣${data.discount?if_exists}折
								</#if>
							</#if>	
						</td>
						<td>
							<#if data.activityType??>
								<#if data.activityType=="cash">
									返现
								<#elseif data.activityType=="coupon">
									返劵
								</#if>
							</#if>
						</td>
						<@shiro.isMainCompany>
							<td>
								<#if data.company??>
									${data.company.abbreviation?if_exists}
								</#if>
							</td>
						</@shiro.isMainCompany>
						<td>${data.start?string('yyyy/MM/dd HH:mm')}</td>
						<td>${data.end?string('yyyy/MM/dd HH:mm')}</td>
						<td>
							<#if !data.stoped>
								<a href="${ctx}/activity/edit/${data.id}" class="btn-link editthis">编辑</a>
								<a href="javascript:;" data-value="${data.id}" class="btn-link stopthis">停止</a>
							</#if>
							<a href="javascript:;" data-value="${data.id}" class="btn-link deletethis">删除</a>
							<a href="${ctx}/activity/detail/${data.id}" class="btn-link">活动详情</a>
							<a href="javascript:;" data-value="${data.id}" class="btn-link pushthis">活动推送</a>
						</td>
					</tr>
				</#list>
				</#if>
			</tbody>
		</table>
		<#if page.totalElements??>
		<ul class="pagination pull-right pagination-sm">
			<li><a>共 ${page.totalElements} 条数据</a></li>
			<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/activity/list">
				<@pg.index>
					<@pg.first>
						<li><a href="${pageUrl}">&laquo;</a></li>
					</@pg.first>
					<@pg.prev>
						<li><a href="${pageUrl}">&lsaquo;</a></li>
					</@pg.prev>
					<@pg.pages>
						<#if  currentPageNumber == pageNumber >
							<li class="active"><a href="#">${pageNumber}</a></li>
						<#else>
							<li><a href="${pageUrl}">${pageNumber}</a></li>
						</#if>
					</@pg.pages>
					<@pg.next>
						<li><a href="${pageUrl}">&rsaquo;</a></li>
					</@pg.next>
					<@pg.last>
						<li><a href="${pageUrl}">&raquo;</a></li>
					</@pg.last>
				</@pg.index>
			</@pg.pager>
		</ul>
		</#if>
	</div>
	</div>
	</div>
</div>
</@override>
<@override name="footer">
<script type="text/javascript">
	var thisButton;
	function deleteActivity() {
	    $.post('${ctx}/activity/delete',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	            	thisButton.parent().parent().remove();
	                $.scojs_message('活动删除成功', $.scojs_message.TYPE_OK);
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	function stopActivity() {
	    $.post('${ctx}/activity/stop',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	            	thisButton.parent().parent().find(".status-td").html("已停止");
	            	thisButton.parent().parent().find(".status-td").removeClass("label-warning label-danger").addClass("label-default");
	            	thisButton.parent().parent().find(".editthis").remove();
	            	thisButton.remove();
	            	
	                $.scojs_message('操作成功', $.scojs_message.TYPE_OK);
	                
			        
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	function pushActivity() {
	    $.post('${ctx}/activity/push',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	                $.scojs_message('推送成功', $.scojs_message.TYPE_OK);
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	
	$(document).ready(function(){
	    $(".deletethis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要删除该活动吗？",
	            action:deleteActivity
	          });
	          confirm.show();
	    });
	    
	    $(".stopthis").click(function(){
	          thisButton = $(this);
	          
	          var confirm = $.scojs_confirm({
	            content: "你真的要停止该活动吗？停止后不可恢复",
	            action:stopActivity
	          });
	          confirm.show();
	     });
	    
	    $(".pushthis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "确认要推送该活动给客户吗？请勿短时间内频繁推送",
	            action:pushActivity
	          });
	          confirm.show();
	    });
	 	
	 	/*$("#table td").each(function(){
                $td = $(this);
                if($.trim($td.text())=="进行中"){
                    $td.parent().css("background","#38B0DE");       
                }
        });*/
	 
	 
	});
</script>
</@override>
<@extends name="../layout.ftl"/>